package com.zz.common.constants;

import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author zl
 * @version 1.0
 */
@Component
public class JwtConstant {

    @Value("${jwt.secret:6ClMQYW4l+I+euMJv8AuAZw0WzqmSEusbH/zSGHO4r0=}")
    private String secret;

    @Value("${jwt.subject:zl}")
    private String subject;

    @Value("${jwt.ttl:${JWT_TTL:3600000}}")  // 默认1小时
    private long ttl;

    // 初始化静态变量
    @PostConstruct
    public void init() {
        JWT_SECRET = this.secret;
        JWT_SUBJECT = this.subject;
        JWT_TTL = this.ttl;
    }

    /**
     * token
     */
    public static final String JWT_ERR_CODE_NULL = "4000";    //Token不存在
    public static final String JWT_ERR_CODE_EXPIRE = "4001";  //Token过期
    public static final String JWT_ERR_CODE_FAIL = "4002";    //验证不通过
    public static final String JWT_ERR_MSG_NULL = "Token不存在";
    public static final String JWT_ERR_MSG_EXPIRE = "Token过期";
    public static final String JWT_ERR_MSG_FAIL = "验证不通过";

    /**
     * JWT
     */
    public static String JWT_SECRET = "6ClMQYW4l+I+euMJv8AuAZw0WzqmSEusbH/zSGHO4r0=";    //密匙
    public static String JWT_SUBJECT = "zl";             //注册者
    public static long JWT_TTL = 24 * 60 * 60 * 1000;    //token有效时间
    public static long JWT_REFRESH_TTL = 24 * 60 * 60 * 1000 * 7;    //token刷新有效时间
}
